package cn.kgc.entity;

import cn.kgc.dto.Attr;
import lombok.*;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.math.BigDecimal;
import java.util.List;

/**
 * 商品上架:
 * （1）更新spu的publishStatus状态
 * （2）将spu对应的sku商品信息保存到ES中
 */
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ToString
@Document(indexName = "skus")
public class SkuEsModel {
    @Id
    private Long skuId; //skuID

    @Field(name = "spuId",type = FieldType.Long)
    private Long spuId; //spuID

    @Field(name = "subTitle",type = FieldType.Text,analyzer = "ik_max_word")
    private String subTitle; //二级标题

    @Field(name = "skuPrice",type = FieldType.Double)
    private BigDecimal skuPrice; //sku价格

    @Field(name = "skuImg",type = FieldType.Keyword)
    private String skuImg;   //sku图片

    @Field(name = "saleCount",type = FieldType.Long)
    private Long saleCount;  //销量

    @Field(name = "hasStock",type = FieldType.Boolean)
    private Boolean hasStock;  //是否还有库存

    @Field(name = "brandId",type = FieldType.Long)
    private Long brandId;     //品牌ID

    @Field(name = "categoryId",type = FieldType.Long)
    private Long categoryId;  //分类的ID

    @Field(name = "categoryName",type = FieldType.Keyword)
    private String categoryName;  //分类的名字

    @Field(name = "brandName",type = FieldType.Keyword)
    private String brandName;  //品牌的名

    @Field(name = "brandImg",type = FieldType.Keyword)
    private String brandImg;   //品牌的图片

    //嵌套类型
    @Field(name = "attrList",type = FieldType.Nested)
    private List<Attrs> attrList; //销售属性信息

    @Getter
    @Setter
    @AllArgsConstructor
    @NoArgsConstructor
    @Builder
    public static class Attrs{
        @Field(name = "attrId",type = FieldType.Long)
        private Long attrId;
        @Field(name = "attrName",type = FieldType.Keyword)
        private String attrName;
        @Field(name = "attrValue",type = FieldType.Keyword)
        private String attrValue;
    }

}
